<?php
require_once 'db.php';
class Works extends DB {

    public $query;
    public $table_name;
    public $begin;
    public $theend;
    public function select_workd() {//phuong thuc
        $this->connects();
        $query = 'SELECT * FROM works LIMIT 0,5';
        $works = $this->query($query);
        return $works;
    }
    
    public function select($page = null) {
        $this->connects();
        $rows = array();
        $this->begin = ($page - 1) * PAGE;
        $query = "SELECT * FROM $this->table_name LIMIT " . $this->begin . "," .$this->theend;
        $result = mysql_query($query);
        while ($row = mysql_fetch_assoc($result))
            $rows[] = $row;
        return $rows;
    }

    public function insert($keywords) {
        $this->connects();
        $query = "INSERT $this->table_name (id, name) values($words[0])";
    }

    public function countWords() {
        $this->connects();
        $rows = array();
        $query = "SELECT * FROM $this->table_name";
        $result = mysql_query($query);
        while ($row = mysql_fetch_assoc($result))
            $rows[] = $row;
        return count($rows);
    }
    public function noidung($pa = null,$id = null){
        $this->connects();
        $where = "";
        if(!empty($id))
            $where = "where id=$id";
        $limit = "";
        if(!empty($pa))
            $limit = 'limit' . $be . ',' . PAGE;
        $be = ($pa - 1 )* PAGE;
        $query = "SELECT * FROM works $this->table_name $where $limit";
        $result = mysql_query($query);
        $result = mysql_fetch_assoc($result);
        return $result;
    }
       public function upload($arry = null){
           $query = "Update works set image='" . $arry['img'] . "'where id =" . $arry['id'];
           mysql_query($query);
           if(mysql_query($query))
               echo 'dc';
           else {
               echo 'sai';
           }
    }
        public function update($array=null){
        $query = "Update works set name='".$array['name'].
                "',location='".$array['location'].
                "', image='".$array['image'].
                "'where id =".$array['id'];
       //echo $query;
        mysql_query($query);
        if( mysql_query($query))
            echo "ok";
        else
            echo "fail";
        
    }
    public function update_nohinh($array = null) {
        $query = "Update works set name='" . $array['name'] .
                "', location='".$array['location'].
                 "' where id=" . $array['id'];
        //echo $query;
        mysql_query($query);
        if (mysql_query($query))
            echo "Lưu tap tin thanh cong";
        else
            echo "Lỗi...! Chưa hoàn thành.";
    }
    
     public function login($username = NULL,$password = NULL) {
        $this->getConnection();
        $query = "SELECT * FROM user WHERE name='".$username."' && password='".$password."'";
        $user = $this->query($query);
        return $user;
    }
}
?>